package webfinal.web;

import webfinal.common.framework.simplemvc.RequestMapping;
import webfinal.entity.User;
import webfinal.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/user")
public class UserController {
    UserService userService=new UserService();
    @RequestMapping("/login.do")
    public String login(HttpServletRequest request , HttpServletResponse response){
        String path = null;
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        User user=userService.login(name,password);
        boolean success = (user!=null);
//        todo 登录成功之后 Session 存储数据判断是否已经登录
        request.getSession().setAttribute("current_user",user);
        path = success?"main":"login";
        if(!success){
            request.setAttribute("msg","用户名或者密码错误");
        }
        System.out.println("测试能否跳转1");
        return path;//视图
    }


}
